package com.itheima;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.function.Consumer;

public class HashSetDemo {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("a");
        list.add("a");
        list.add("a");
        list.add("a");
        System.out.println(list);
        ArrayList<String>  newlist = new ArrayList<>(new HashSet<String>(list));
        System.out.println(newlist);

        //创建hashset对象
        HashSet<String> hashSet = new HashSet<>();
        //保存数据，可以去重复
        hashSet.add("张琪");
        hashSet.add("尤柯");
        hashSet.add("赵鑫");
        hashSet.add("赵鑫");
        hashSet.add("赵鑫");
        hashSet.add("赵鑫");
        hashSet.add("赵鑫");
        hashSet.add("张植");
        System.out.println(hashSet);
        //取数据,迭代器
        Iterator<String> iterator = hashSet.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            System.out.println(next);

        }
//        for (int i = 0; i < hashSet.size(); i++) {
//
//        }用不了

        //取数据
        for (String name:hashSet) {
            System.out.println("name="+name);
        }
        int[] arr = {1,2,3,4,5,6,7,8};
        for (int i:arr) {
            System.out.println(arr);
        }
        //
        hashSet.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        hashSet.forEach(s -> System.out.println(s));
        hashSet.forEach(System.out::println);
        Student student = new Student("zhangsan",28);
        System.out.println(student.toString());
    }
}